﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true"
    CodeBehind="Admin_ExportXls.aspx.cs" Inherits="Xiaov.SmartWeb.Application.PluginSrc.StatisticalSystem.ReportDesign.Admin_ExportXls" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script type="text/javascript" src="/Resources/xiaovcn/scripts/usercheck.js"></script>
    <script>
        $(function () {
            bindgrid();
            $('#p').panel({ height: userScreenHeight - 10,width:700 });
            //            binddownload();
        });

        function binddownload() {
            var year = $('#tb_nf').val();
            var month = $('#tb_yf').val();
            var dwbm = '<%=DWBM%>';
            var url = Xiaov.SmartWeb.Application.PluginSrc.StatisticalSystem.ReportDesign.Admin_ExportXls.DownFile(dwbm, year, month).value;
            //alert(url);
            if (url != "#") {
                alert(year + '年' + month + '月Excel报表准备就绪，请点击下载或者重新导出选中的报表！');
                $('#down').linkbutton('enable');
                $('#down').attr('href', url);
            }
            else
                $('#down').linkbutton('disable');
        }

        function callback(res) {
            if (res.value) {
                $.messager.alert('提示', '操作成功！,请稍后刷新页面下载Excel');
            }
            else {
                $.messager.alert(res.error);
            }
        }
        function bindgrid() {
            $('#tt').tree({
                url: 'Json/ExportBBBMB.aspx?dwbm=<%=DWBM%>', lines: true,
                checkbox: true
            });
        }

        function Export() {
            var nodes = $('#tt').tree('getChecked');
            var year = $('#tb_nf').val();
            var month = $('#tb_yf').val();
            //alert(year+month);
            var str = "";
            var dwbm = '<%=DWBM%>';
            for (var i = 0; i < nodes.length; i++) {
                str += nodes[i].id + ',';
            }
            //alert(str);
            //            Xiaov.SmartWeb.Application.PluginSrc.StatisticalSystem.ReportDesign.Admin_ExportXls.Export(str, dwbm, year, month, callback);
            window.location.href = "ExcelExport.aspx?dwbm=" + dwbm + "&year=" + year + "&month=" + month + "&bbbm=" + str;
        }

        function treeChecked(selected, treeMenu) {
            var roots = $('#' + treeMenu).tree('getRoots'); //返回tree的所有根节点数组
            if (selected.checked) {
                for (var i = 0; i < roots.length; i++) {
                    var node = $('#' + treeMenu).tree('find', roots[i].id); //查找节点
                    $('#' + treeMenu).tree('check', node.target); //将得到的节点选中
                }
            } else {
                for (var i = 0; i < roots.length; i++) {
                    var node = $('#' + treeMenu).tree('find', roots[i].id);
                    $('#' + treeMenu).tree('uncheck', node.target);
                }
            }
        }

    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div style="padding-bottom: 5px; font-size: 12px;">
        <select class="easyui-combobox" id="dwbm" name="state" style="width: 200px;" data-options="">
        </select>
        <script type="text/javascript">
            $(function () {
                var request_dwbm = '<%=DWBM%>';
//                alert(request_dwbm);
                $('#dwbm').combobox({
                    url: 'Json/ManageDeptList.aspx',
                    valueField: 'DWBM',
                    textField: 'DWMC',
                    panelHeight: '200',
                    formatter: formatItem,
                    onSelect: function (rec) { window.location.href('/PluginSrc/StatisticalSystem/ReportDesign/Admin_ExportXls.aspx?dwbm=' + rec.DWBM) },
                    onLoadSuccess: function (param) {
                        $('#dwbm').combobox('setValue', request_dwbm);
                    }
                });

                function formatItem(row) {
                    var s = '<span style="color:#888">' + row.DWBM + '</span>-<span style="font-weight:bold">' + row.DWMC + '</span>';
                    return s;
                }
            });
        </script>
        年份:<asp:TextBox ID="tb_nf" runat="server" CssClass="easyui-numberspinner" editable="false"
            ClientIDMode="Static"></asp:TextBox>
        月份:<asp:TextBox ID="tb_yf" runat="server" CssClass="easyui-numberspinner" editable="false"
            ClientIDMode="Static"></asp:TextBox>
        <a href="#" class="easyui-linkbutton" iconcls="icon-redo" onclick="Export();">导出选中的报表</a>
        <%-- <a href="#" class="easyui-linkbutton" iconcls="icon-save" disabled="true" id="down">
      下载</a> <a href="#" class="easyui-linkbutton" iconcls="icon-reload" id="refresh" onclick="binddownload();">
        刷新</a>--%>
    </div>
    <div style="padding-top: 5px" class="easyui-panel" id="p" title="该单位有以下报表:" iconcls="icon-applicationgo">
        <input title="全选/反选" type="checkbox" onclick="treeChecked(this, 'tt')" />
        全选/反选
        <ul id="tt">
        </ul>
    </div>
</asp:Content>
